//
//  FilesViewController.m
//  uplife
//
//  Created by ZhangCheng on 2018/12/26.
//  Copyright © 2018年 ZhangCheng. All rights reserved.
//

#import "FilesViewController.h"

@interface FilesViewController ()
@property(nonatomic,strong)NSDictionary *dataDic;
@end

@implementation FilesViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self sendRequestForLoadData];
}
-(void)sendRequestForLoadData{
    NSString *urlString = [NSString stringWithFormat:@"%@/realty/get-room-file.do?roomId=%@",JSXF_HOST,self.roomId];
    
    [SVProgressHUD show];
    
    [ZCWebServiceHelper requestWithMethod:GET andUrlStr:urlString andParameters:nil andFinished:^(id response, NSURLSessionDataTask *dataTask) {
        [SVProgressHUD dismiss];
        if (![response[@"data"] isKindOfClass:[NSString class]]) {
            NSDictionary *dic = response;
            self.dataDic = dic[@"data"];
            [self resetView];
        }
        
    }];
}

-(void)resetView{
    for (NSInteger i=11; i<17; i++) {
        UILabel *label = [self.tableView viewWithTag:i];
        if (label!=nil) {
            NSNumber *fileCount = self.dataDic[@"files"][i-11][@"fileCount"];
            label.text = [NSString stringWithFormat:@"%@",fileCount];
            UITableViewCell *cell = [self.tableView viewWithTag:(i+10)];
            cell.accessoryType = fileCount.integerValue==0?UITableViewCellAccessoryNone:UITableViewCellAccessoryDisclosureIndicator;
        }
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    NSNumber *fileCount = self.dataDic[@"files"][cell.tag-21][@"fileCount"];
    if (fileCount.integerValue!=0) {
        [self.fatherViewController performSegueWithIdentifier:@"toFilesListViewController" sender:self.dataDic[@"files"][cell.tag-21]];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
